var designClass = "design_class", hideClass = "hide_class", browseClass = "browse_class", addClass = "add_class", editClass = "edit_class";
var upWindow = window.parent.frames["zwIframe"];
if (!upWindow) {
	upWindow = window.parent.frames["componentDiv"].frames["zwIframe"];
}
// 关闭自定义扩张控件弹出窗口
function fy_dialog_close() {
	window.parent.$(".layui-layer-iframe").parent().find(".layui-layer-close").trigger(
			"click");
}

function getUpFieldsByFieldval(name) {
	return upWindow.$("[fieldval*='displayName:\"" + name + "\"']");
}

function setUpFieldValue2(field, value, displayValue, index) {

	try {

		var fieldVal = field.attr("fieldVal");
		var editTag = field.hasClass(editClass);
		var addTag = field.hasClass(addClass);
		value = (value);
		displayValue = displayValue ? (displayValue) : displayValue;
		if (fieldVal != null && typeof (fieldVal) != 'undefined') {
			fieldVal = eval("(" + fieldVal + ")");
		} else {
			return null;
		}
		var tag = true;
		switch (fieldVal.inputType) {
		case "text":
		case "textarea":
			if (editTag) {
				var inField = field.find("#" + fieldVal.name);
				inField.val(value);
				inField.trigger("blur");
			} else if (addTag) {
				var inField = field.find("#" + fieldVal.name);
				inField.val(value);
				inField.trigger("blur");
			}
			break;
		case "checkbox":
			if (editTag) {
				field.find("#" + fieldVal.name).attr("checked", true);
				field.find("#" + fieldVal.name).trigger("click");
			}
			break;
		case "radio":
			if (editTag) {
				field.find(":radio").eq(index).attr("checked", true);
				field.find(":radio").eq(index).trigger("click");
			}
			break;
		case "select":
			if (editTag) {
				var options = field.find("#" + fieldVal.name + " option");
				for ( var k = 0; k < options.length; k++) {
					if (options.eq(k).text() == value)
						options.eq(k).attr("selected", true);
				}
				field.find("#" + fieldVal.name).trigger("change");
			}
			break;
		case "date":
			if (editTag) {
				field.find("#" + fieldVal.name).val(value);
				field.find("#" + fieldVal.name).trigger("blur");
			}
			break;
		case "datetime":
			if (editTag) {
				field.find("#" + fieldVal.name).val(value);
				field.find("#" + fieldVal.name).trigger("blur");
			}
			break;
		case "member":
		case "multimember":
		case "account":
		case "multiaccount":
		case "department":
		case "multidepartment":
		case "post":
		case "multipost":
		case "level":
		case "multilevel":
			if (editTag) {
				// alert(editTag);
				field.find("#" + fieldVal.name).val(value);
			}
			break;
		}
	} catch (e) {
		// TODO: handle exception
	}
}
var msg = upWindow.$("#resultMsgDiv");
if (post && post != '') {
//	setUpFieldValue2(getUpFieldsByFieldval("姓名").eq(0), post);
	setUpFieldValue2(getUpFieldsByFieldval("工号").eq(0), code);
	setUpFieldValue2(getUpFieldsByFieldval("岗位").eq(0), post);
	setUpFieldValue2(getUpFieldsByFieldval("所在制造部").eq(0), corpName);
	setUpFieldValue2(getUpFieldsByFieldval("所在部门").eq(0), deptName);;
	if (msg) {
		msg.hide();
	}
} else {
	if (msg.length == 0) {
		getUpFieldsByFieldval("工号").parentNode.parentNode.append("<div id='resultMsgDiv' style='font-family:微软雅黑;font-size: 10.5pt;color: red;'>未查找到人员工号或工号不正确，请和制造部信息部联系，设置OA账号的人员编号为用户的工号</div>");
	} else {
		msg.show();
	}
}
fy_dialog_close();